import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:local_task/common/tools/extensions.dart';
import 'package:local_task/controller/home_controller.dart';
import 'package:local_task/pages/search.dart';
import 'package:local_task/pages/task.dart';
import 'package:get/get.dart';
import '../controller/task_controller.dart';

class Home extends StatelessWidget {
  Home({super.key});

  final taskController = Get.put(TaskController());
  final homeController = Get.put(HomeController());

  @override
  Widget build(context) {
    return Scaffold(
      appBar: AppBar(actions:  [
        Padding(padding: const EdgeInsets.only(right: 30), child: IconButton(onPressed: () {
          taskController.taskList.removeRange(0, taskController.taskList.length);
          Get.to(Search());
        }, icon: const Icon(Icons.search),),)
      ]),
      body: Task(),
      drawer: _drawerWidget(context),
    );
  }

  Widget _drawerWidget(BuildContext context) {
    const drawerHeader = UserAccountsDrawerHeader(
      accountName: Text(
        "测试用户",
      ),
      accountEmail: Text(
        "xxxxxxx@qq.com",
      ),
      currentAccountPicture: CircleAvatar(
        child: FlutterLogo(size: 42.0),
      ),
    );

    return Obx(() {
      return Container(
        width: 50.0.wp,
        child: ListView(
          children: [
            drawerHeader,
            ListTile(title: Text("深夜模式"), trailing: CupertinoSwitch(
              value: homeController.darkModelObs.value,
              onChanged: (value) {
                homeController.darkModelObs.value = value;
                Get.changeTheme(Get.isDarkMode? ThemeData.light(): ThemeData.dark());
              },
            ),),

          ],
        ),
      );
    });
  }
}
